function FigOutput(sw, opt, fs, freqs, xz, y)
%FIGOUTPUT plot the figures of results
%   plotAna indicates whether to plot analysis frequency
%   plotCom indicates whether to plot comparison between waveforms (M Caetano's Method)

if sw.plotAna
    figure('Name', "frequency display");
    plot(fs/(2*pi)*freqs', '.');

    xlabel('frame number');
    ylabel('frequency(Hz)');
end

if sw.plotCom && opt.expandRatio==1 && opt.freqShift == 0
    figure('Name', "waveform compare");
    
    % Plot Orig vs Sinusoidal
    time = (0:length(y)-1)/fs;
    subplot(2,1,1);
    plot(time,xz,'o-r')
    hold on
    plot(time,y,'.-k')
    hold off
    title('Original vs Sinusoidal')
    legend('Original','Sinusoidal')
    xlabel('Time (s)')
    ylabel('Amplitude (linear)')

    % Make residual
    res = xz - y;

    % Plot Orig vs Residual
    subplot(2,1,2);
    plot(time,xz,'r')
    hold on
    plot(time,res,'k')
    hold off
    title(['Original vs Residual:SMR=', num2str(sqrt(1/length(y)*(res'*res)), 3)])
    legend('Original','Residual')
    xlabel('Time (s)')
    ylabel('Amplitude (linear)')
end
end

